define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'goods/goods/index' + location.search,
                    add_url: 'goods/goods/add',
                    edit_url: 'goods/goods/edit',
                    del_url: 'goods/goods/del',
                    multi_url: 'goods/goods/multi',
                    import_url: 'goods/goods/import',
                    table: 'goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order', title: __('Order'), operate: 'LIKE'},
                        {field: 'gamestype.name', title: __('Gamestype.name'), operate: 'LIKE'},
                        {field: 'goods_type', title: __('商品类型'), operate: 'LIKE'},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'current_rank', title: __('Current_rank'), operate: 'LIKE'},
                        {field: 'target_rank', title: __('Target_rank'), operate: 'LIKE'},
                        {field: 'client', title: __('Client'), operate: 'LIKE'},
                        {field: 'qu', title: __('Qu'), operate: 'LIKE'},
                        {field: 'ask_ok_time', title: __('Ask_ok_time'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'),"6":__('Status 6'),"7":__('Status 7')}, formatter: Table.api.formatter.status},
                        {field: 'game_account', title: __('Game_account'), operate: 'LIKE'},
                        {field: 'dl_price', title: __('Dl_price'), operate:'BETWEEN'},
                        {field: 'bond', title: __('Bond'), operate:'BETWEEN'},
                        {field: 'user.nickname', title: __('User_id'), operate: 'LIKE'},
                        {field: 'moblie', title: __('Moblie'), operate: 'LIKE'},
                        {field: 'dl_ask', title: __('dl_ask'), operate: false,
                            formatter : function(value, row, index, field){
                                return "<span style='display: block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;' title='" + row.remark + "'>" + value + "</span>";
                            },
                            cellStyle : function(value, row, index, field){
                                return {
                                    css: {
                                        "white-space": "nowrap",
                                        "text-overflow": "ellipsis",
                                        "overflow": "hidden",
                                        "max-width":"150px"
                                    }
                                };
                            }

                        },
                        {field: 'other', title: __('Other'), operate: 'LIKE'},
                        {field: 'addtime', title: __('Addtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);


        },
        add: function () {
            Controller.api.bindevent();

        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }

        }
    };
    return Controller;

});